package com.prs.crm.action.approval;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.action.warning.AutoCodeAction;
import com.prs.crm.context.AppContext;
import com.prs.crm.context.FileUtil;
import com.prs.crm.domain.approval.Application;
import com.prs.crm.domain.approval.Approve;
import com.prs.crm.domain.approval.ChaiLv;
import com.prs.crm.domain.approval.Procure;
import com.prs.crm.domain.approval.Purpose;
import com.prs.crm.domain.approval.Quote;
import com.prs.crm.domain.approval.ShenQingType;
import com.prs.crm.domain.archives.ArchivesManager;
import com.prs.crm.domain.archives.ArchivesType;
import com.prs.crm.domain.flow.FlowNodePerson;
import com.prs.crm.domain.flow.FlowVerifyDetail;
import com.prs.crm.domain.flow.WorkFlow;
import com.prs.crm.domain.flow.WorkFlowAndPerson;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.receipt.ReceiptMoudle;
import com.prs.crm.domain.receipt.ReceiptRegister;
import com.prs.crm.domain.warning.AutoCode;
import com.prs.crm.service.approval.ApplicationService;
import com.prs.crm.service.approval.ChailvService;
import com.prs.crm.service.approval.ProcureService;
import com.prs.crm.service.approval.PurposeService;
import com.prs.crm.service.approval.QuoteService;
import com.prs.crm.service.approval.ShenQingTypeService;
import com.prs.crm.service.archives.ArchivesManagerService;
import com.prs.crm.service.archives.ArchivesTypeService;
import com.prs.crm.service.assets.AssetsBigClassService;
import com.prs.crm.service.flow.FlowNodePersonService;
import com.prs.crm.service.flow.FlowVerifyDetailService;
import com.prs.crm.service.flow.WorkFlowAndPersonService;
import com.prs.crm.service.flow.WorkFlowNodeService;
import com.prs.crm.service.flow.WorkFlowService;
import com.prs.crm.service.warning.AutoCodeService;

/**
 * @author 廖苹宏
 * @version 2012-5-2 15:53:37 审签流转
 * */
public class ApplicationAction extends BaseAction {
	private Application application;
	private ApplicationService applicationService;
	private PaginationSupport pagination;
	private File upload;
	private String uploadFileName;
	private PurposeService purposeService; // 费用项目列表
	private List<Purpose> purposelist;
	private Integer[] ids;
	private String rec;
	private String type; // 控制查看页面的按钮显示
	private ChailvService chailvService; // 差旅
	private ChaiLv chailv;
	private Set<ChaiLv> chailvs;
	private QuoteService quoteService; // 报价
	private List<Quote> quotes;
	private ProcureService procureService; // 采购
	private List<Procure> procures;
	private Integer[] myApplyIds;
	private AssetsBigClassService assetsBigClassService;

	private FlowVerifyDetail detail;
	private List<WorkFlow> workFlow;
	private WorkFlow workFlows;
	private WorkFlowService workflowService;
	private List<FlowNodePerson> nodePerson;
	private FlowNodePersonService flowNodePersonService;
	private WorkFlowNodeService workFlowNodeService;
	private FlowVerifyDetailService flowVerifyDetailService;
	private WorkFlowAndPerson workFlowAndPerson;
	private WorkFlowAndPersonService workFlowAndPersonService;
	private FlowVerifyDetail flowVerifyDetail;

	private ArchivesManager archivesManager;
	private ArchivesManagerService archivesManagerService;
	private ArchivesType archivesType;
	private ArchivesTypeService archivesTypeService;
	private Integer idd;
	private AutoCodeService autoCodeService;
	private String codeNum;
	private ShenQingTypeService shenQingTypeService;
	private List<WorkFlowAndPerson> workFlowAndPersons;
	private List<FlowVerifyDetail> flowVerifyDetails;
	public List<WorkFlowAndPerson> getWorkFlowAndPersons() {
		return workFlowAndPersons;
	}

	public void setWorkFlowAndPersons(List<WorkFlowAndPerson> workFlowAndPersons) {
		this.workFlowAndPersons = workFlowAndPersons;
	}

	public List<FlowVerifyDetail> getFlowVerifyDetails() {
		return flowVerifyDetails;
	}

	public void setFlowVerifyDetails(List<FlowVerifyDetail> flowVerifyDetails) {
		this.flowVerifyDetails = flowVerifyDetails;
	}

	public ShenQingTypeService getShenQingTypeService() {
		return shenQingTypeService;
	}

	public void setShenQingTypeService(ShenQingTypeService shenQingTypeService) {
		this.shenQingTypeService = shenQingTypeService;
	}

	public ArchivesManager getArchivesManager() {
		return archivesManager;
	}

	public void setArchivesManager(ArchivesManager archivesManager) {
		this.archivesManager = archivesManager;
	}

	public AutoCodeService getAutoCodeService() {
		return autoCodeService;
	}

	public void setAutoCodeService(AutoCodeService autoCodeService) {
		this.autoCodeService = autoCodeService;
	}

	public String getCodeNum() {
		return codeNum;
	}

	public void setCodeNum(String codeNum) {
		this.codeNum = codeNum;
	}

	public ArchivesManagerService getArchivesManagerService() {
		return archivesManagerService;
	}

	public void setArchivesManagerService(
			ArchivesManagerService archivesManagerService) {
		this.archivesManagerService = archivesManagerService;
	}

	public ArchivesType getArchivesType() {
		return archivesType;
	}

	public void setArchivesType(ArchivesType archivesType) {
		this.archivesType = archivesType;
	}

	public ArchivesTypeService getArchivesTypeService() {
		return archivesTypeService;
	}

	public void setArchivesTypeService(ArchivesTypeService archivesTypeService) {
		this.archivesTypeService = archivesTypeService;
	}

	public Integer getIdd() {
		return idd;
	}

	public void setIdd(Integer idd) {
		this.idd = idd;
	}

	public FlowVerifyDetail getDetail() {
		return detail;
	}

	public void setDetail(FlowVerifyDetail detail) {
		this.detail = detail;
	}

	public List<WorkFlow> getWorkFlow() {
		return workFlow;
	}

	public void setWorkFlow(List<WorkFlow> workFlow) {
		this.workFlow = workFlow;
	}

	public WorkFlow getWorkFlows() {
		return workFlows;
	}

	public void setWorkFlows(WorkFlow workFlows) {
		this.workFlows = workFlows;
	}

	public WorkFlowService getWorkflowService() {
		return workflowService;
	}

	public void setWorkflowService(WorkFlowService workflowService) {
		this.workflowService = workflowService;
	}

	public List<FlowNodePerson> getNodePerson() {
		return nodePerson;
	}

	public void setNodePerson(List<FlowNodePerson> nodePerson) {
		this.nodePerson = nodePerson;
	}

	public FlowNodePersonService getFlowNodePersonService() {
		return flowNodePersonService;
	}

	public void setFlowNodePersonService(
			FlowNodePersonService flowNodePersonService) {
		this.flowNodePersonService = flowNodePersonService;
	}

	public WorkFlowNodeService getWorkFlowNodeService() {
		return workFlowNodeService;
	}

	public void setWorkFlowNodeService(WorkFlowNodeService workFlowNodeService) {
		this.workFlowNodeService = workFlowNodeService;
	}

	public FlowVerifyDetailService getFlowVerifyDetailService() {
		return flowVerifyDetailService;
	}

	public void setFlowVerifyDetailService(
			FlowVerifyDetailService flowVerifyDetailService) {
		this.flowVerifyDetailService = flowVerifyDetailService;
	}

	public WorkFlowAndPerson getWorkFlowAndPerson() {
		return workFlowAndPerson;
	}

	public void setWorkFlowAndPerson(WorkFlowAndPerson workFlowAndPerson) {
		this.workFlowAndPerson = workFlowAndPerson;
	}

	public WorkFlowAndPersonService getWorkFlowAndPersonService() {
		return workFlowAndPersonService;
	}

	public void setWorkFlowAndPersonService(
			WorkFlowAndPersonService workFlowAndPersonService) {
		this.workFlowAndPersonService = workFlowAndPersonService;
	}

	public FlowVerifyDetail getFlowVerifyDetail() {
		return flowVerifyDetail;
	}

	public void setFlowVerifyDetail(FlowVerifyDetail flowVerifyDetail) {
		this.flowVerifyDetail = flowVerifyDetail;
	}

	public AssetsBigClassService getAssetsBigClassService() {
		return assetsBigClassService;
	}

	public void setAssetsBigClassService(
			AssetsBigClassService assetsBigClassService) {
		this.assetsBigClassService = assetsBigClassService;
	}

	public Integer[] getMyApplyIds() {
		return myApplyIds;
	}

	public void setMyApplyIds(Integer[] myApplyIds) {
		this.myApplyIds = myApplyIds;
	}

	public Application getApplication() {
		return application;
	}

	public void setApplication(Application application) {
		this.application = application;
	}

	public ApplicationService getApplicationService() {
		return applicationService;
	}

	public void setApplicationService(ApplicationService applicationService) {
		this.applicationService = applicationService;
	}

	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public String getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public Integer[] getIds() {
		return ids;
	}

	public void setIds(Integer[] ids) {
		this.ids = ids;
	}

	public PurposeService getPurposeService() {
		return purposeService;
	}

	public void setPurposeService(PurposeService purposeService) {
		this.purposeService = purposeService;
	}

	public List<Purpose> getPurposelist() {
		return purposelist;
	}

	public void setPurposelist(List<Purpose> purposelist) {
		this.purposelist = purposelist;
	}

	public String getRec() {
		return rec;
	}

	public void setRec(String rec) {
		this.rec = rec;
	}

	public ChailvService getChailvService() {
		return chailvService;
	}

	public void setChailvService(ChailvService chailvService) {
		this.chailvService = chailvService;
	}

	public ChaiLv getChailv() {
		return chailv;
	}

	public void setChailv(ChaiLv chailv) {
		this.chailv = chailv;
	}

	public Set<ChaiLv> getChailvs() {
		return chailvs;
	}

	public void setChailvs(Set<ChaiLv> chailvs) {
		this.chailvs = chailvs;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public QuoteService getQuoteService() {
		return quoteService;
	}

	public void setQuoteService(QuoteService quoteService) {
		this.quoteService = quoteService;
	}

	public List<Quote> getQuotes() {
		return quotes;
	}

	public void setQuotes(List<Quote> quotes) {
		this.quotes = quotes;
	}

	public ProcureService getProcureService() {
		return procureService;
	}

	public void setProcureService(ProcureService procureService) {
		this.procureService = procureService;
	}

	public List<Procure> getProcures() {
		return procures;
	}

	public void setProcures(List<Procure> procures) {
		this.procures = procures;
	}

	public PaginationSupport getPagination() {
		return pagination;
	}

	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}

	// /////////////////以下为业务////////////////////////////
	/** 现金借支单 **/
	// 保存
	@Action(value = "saveCash", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editcash") })
	public String saveCash() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("现金借支单");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendCash", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editcash") })
	public String sendCash() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);
		application.setResign("现金借支单");
		this.applicationService.save(application);

		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	@Action("editCash")
	public String editCash() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 删除
	@Action(value = "removeCash", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "listappliction") })
	public String removeCash() {
		this.applicationService.remove(application);
		return SUCCESS;
	}

	// 查看
	@Action("viewCash")
	public String viewCash() {
		return SUCCESS;
	}

	/** 支票借支单 */
	// 保存
	@Action(value = "saveCheque", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editCheque") })
	public String saveCheque() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("支票借支单");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendCheque", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editCheque") })
	public String sendCheque() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);
		application.setOabox(0);
		application.setResign("支票借支单");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	/** 支票借支单 **/
	@Action("editCheque")
	public String editCheque() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 查看
	@Action("viewCheque")
	public String viewCheque() {
		return SUCCESS;
	}

	/** 电汇借支单 */
	// 保存
	@Action(value = "saveDianHui", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editDianHui") })
	public String saveDianHui() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("电汇借支单");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendDianHui", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editDianHui") })
	public String sendDianHui() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);
		application.setOabox(0);
		application.setResign("电汇借支单");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	@Action("editDianHui")
	public String editDianHui() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 查看
	@Action("viewDianHui")
	public String viewDianHui() {
		return SUCCESS;
	}

	/** 费用报销单 */
	@Action("editcost")
	public String editcost() {
		purposelist = this.purposeService.getAllpurpose();
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "savecost", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editcost") })
	public String savecost() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("费用报销单");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendcost", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editcost") })
	public String sendcost() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);
		application.setOabox(0);
		application.setResign("费用报销单");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewcost")
	public String viewcost() {
		purposelist = this.purposeService.getAllpurpose();
		return SUCCESS;
	}

	/** 差旅费报销单 */
	@Action("editChailv")
	public String editChailv() {
		if (this.application == null) {
			this.rec = "";
		}
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveChailv", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editChailv") })
	public String savechailv() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("差旅费报销单");
		if (car != null) {
			initchailvs();
		}
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendChailv", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editChailv") })
	public String sendchailv() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);
		application.setResign("差旅费报销单");
		if (car != null) {
			initchailvs();
		}
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewChailv")
	public String viewChailv() {

		return SUCCESS;
	}

	/** 工作报告 */
	@Action("editReport")
	public String editReport() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "savereport", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editReport") })
	public String savereport() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("工作报告");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendreport", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editReport") })
	public String sendreport() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);application.setOabox(0);
		application.setResign("工作报告");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewReport")
	public String viewReport() {
		return SUCCESS;
	}

	/** 报价审批单 */
	@Action("editQuote")
	public String editQuote() {
		if (this.application == null) {
			this.rec = "";
		}
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveQuote", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editQuote") })
	public String saveQuote() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("报价审批单");
		this.applicationService.save(application);
		if (qname != null) {
			this.initquote();
		}
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendQuote", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editQuote") })
	public String sendQuote() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);
		application.setOabox(0);
		application.setResign("报价审批单");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		if (qname != null) {
			this.initquote();
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewQuote")
	public String viewQuote() {
		return SUCCESS;
	}

	/** 故障维护表 */
	@Action("editFault")
	public String editFault() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveFault", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editFault") })
	public String saveFault() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("软硬件故障维护表");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendFault", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editFault") })
	public String sendFault() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);
		application.setOabox(0);
		application.setResign("软硬件故障维护表");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewFault")
	public String viewFault() {
		return SUCCESS;
	}

	/** 设备采购单 */
	@Action("editProcure")
	public String editProcure() {
		if (this.application == null) {
			this.rec = "";
		}
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveProcure", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editProcure") })
	public String saveProcure() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("设备采购单");
		this.applicationService.save(application);
		if (bei != null) {
			this.initprocure();
		}
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendProcure", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editProcure") })
	public String sendProcure() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);application.setOabox(0);
		application.setResign("设备采购单");
		this.applicationService.save(application);
		if (bei != null) {
			this.initprocure();
		}
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewProcure")
	public String viewProcure() {
		if (this.application == null) {
			this.rec = "";
		}
		return SUCCESS;
	}

	/** 业务招待表 */
	@Action("editBusiness")
	public String editBusiness() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveBusiness", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editBusiness") })
	public String saveBusiness() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("业务招待费申请表");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendBusiness", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editBusiness") })
	public String sendBusiness() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);application.setOabox(0);
		application.setResign("业务招待费申请表");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewBusiness")
	public String viewBusiness() {
		return SUCCESS;
	}

	/** 出差申请表 */
	@Action("editChuchai")
	public String editChuchai() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveChuchai", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editChuchai") })
	public String saveChuchai() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("出差申请书");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendChuchai", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editChuchai") })
	public String sendChuchai() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);application.setOabox(0);
		application.setResign("出差申请书");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewChuchai")
	public String viewChuchai() {
		return SUCCESS;
	}

	/** 员工请假单 */
	@Action("editLeave")
	public String editLeave() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveLeave", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editLeave") })
	public String saveLeave() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("员工请假单");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendLeave", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editLeave") })
	public String sendLeave() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);application.setOabox(0);
		application.setResign("员工请假单");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewLeave")
	public String viewLeave() {
		return SUCCESS;
	}

	/** 加班申请单 */
	@Action("editOvertime")
	public String editOvertime() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveOvertime", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editOvertime") })
	public String saveOvertime() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("加班申请");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendOvertime", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editOvertime") })
	public String sendOvertime() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);application.setOabox(0);
		application.setResign("加班申请");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewOvertime")
	public String viewOvertime() {
		return SUCCESS;
	}

	/** 人员信息变更表 */
	@Action("editPersonnel")
	public String editPersonnel() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "savePersonnel", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editPersonnel") })
	public String savePersonnel() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("人事信息变更申请表");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendPersonnel", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editPersonnel") })
	public String sendPersonnel() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);application.setOabox(0);
		application.setResign("人事信息变更申请表");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewPersonnel")
	public String viewPersonnel() {
		return SUCCESS;
	}

	/** 辞退申请单 */
	@Action("editDismiss")
	public String editDismiss() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveDismiss", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editDismiss") })
	public String saveDismiss() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("员工辞退申请单");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendDismiss", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editDismiss") })
	public String sendDismiss() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);application.setOabox(0);
		application.setResign("员工辞退申请单");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewDismiss")
	public String viewDismiss() {
		return SUCCESS;
	}

	/** 转正申请单 */
	@Action("editBecomes")
	public String editBecomes() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveBecomes", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editBecomes") })
	public String saveBecomes() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("员工转正申请表");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendBecomes", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editBecomes") })
	public String sendBecomes() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);application.setOabox(0);
		application.setResign("员工转正申请表");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewBecomes")
	public String viewBecomes() {
		return SUCCESS;
	}

	/** 试用期考核表 */
	@Action("editProbation")
	public String editProbation() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveProbation", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editProbation") })
	public String saveProbation() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("员工试用期考核表");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendProbation", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editProbation") })
	public String sendProbation() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);application.setOabox(0);
		application.setResign("员工试用期考核表");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewProbation")
	public String viewProbation() {
		return SUCCESS;
	}

	/** 工资变更申请单 */
	@Action("editWage")
	public String editWage() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveWage", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editWage") })
	public String saveWage() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("变更工资申请单");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendWage", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editWage") })
	public String sendWage() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);application.setOabox(0);
		application.setResign("变更工资申请单");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewWage")
	public String viewWage() {
		return SUCCESS;
	}

	/** 公司招聘表 */
	@Action("editRecruitment")
	public String editRecruitment() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveRecruitment", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editRecruitment") })
	public String saveRecruitment() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("公司招聘申请表");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendRecruitment", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editRecruitment") })
	public String sendRecruitment() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);application.setOabox(0);
		application.setResign("公司招聘申请表");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewRecruitment")
	public String viewRecruitment() {
		return SUCCESS;
	}

	/** 员工离职表 */
	@Action("editLizhi")
	public String editLizhi() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveLizhi", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editLizhi") })
	public String saveLizhi() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("员工离职审批表");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendLizhi", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editLizhi") })
	public String sendLizhi() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);application.setOabox(0);
		application.setResign("员工离职审批表");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewLizhi")
	public String viewLizhi() {
		return SUCCESS;
	}

	/** 奖惩建议单 */
	@Action("editJiangcheng")
	public String editJiangcheng() {
		this.workFlow = this.getWorkflowService().getWorkFlow("审批流转流程");
		codeNum=getCode("SP");
		return SUCCESS;
	}

	// 保存
	@Action(value = "saveJiangcheng", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editJiangcheng") })
	public String saveJiangcheng() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(0);
		application.setSqType(0);
		application.setSpr(0);
		application.setResign("奖惩建议单");
		this.applicationService.save(application);
		return SUCCESS;
	}

	// 发送
	@Action(value = "sendJiangcheng", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editJiangcheng") })
	public String sendJiangcheng() {
		if (upload != null) {
			application.setAttach(FileUtil.getInstance().createAttach(upload,
					uploadFileName));
		}
		application.setAppState(1);
		application.setSqType(1);
		application.setSpr(1);
		application.setOabox(0);
		application.setResign("奖惩建议单");
		this.applicationService.save(application);
		List<FlowNodePerson> fp = this.getFlowNodePersonService()
				.getFlowNodePerson(application.getWorkFlow());
		for (FlowNodePerson op : fp) {
			WorkFlowAndPerson workFlowAndPerson = new WorkFlowAndPerson();
			workFlowAndPerson.setWorkFlow(op.getWorkFlow());
			workFlowAndPerson.setNodePersonId(op.getNodeperson_id());
			workFlowAndPerson.setFlowstate("1");// 审签状态
			workFlowAndPerson.setFlowsequen(op.getWorkFlowNode().getSequence()
					+ "");
			workFlowAndPerson.setType(op.getWorkFlowNode().getType() + "");
			String[] persons = op.getNodeperson_id().split(",");
			System.out.println(persons.length);
			workFlowAndPerson.setPersonNum(persons.length);
			workFlowAndPerson.setApplication(application);
			this.getWorkFlowAndPersonService().save(workFlowAndPerson);
		}
		return SUCCESS;
	}

	// 查看
	@Action("viewJiangcheng")
	public String viewJiangcheng() {
		return SUCCESS;
	}

	/** 采购申请 */
	// 查看
	@Action("viewPurchaseApply")
	public String viewPurchaseApply() {
		return SUCCESS;
	}

	/** 采购入库 */
	// 查看
	@Action("viewProcureStore")
	public String viewProcureStore() {
		return SUCCESS;
	}

	/** 物品信息 */
	// 查看
	@Action("viewArticleInfo")
	public String viewArticleInfo() {
		return SUCCESS;
	}

	/** 库存维护 */
	// 查看
	@Action("viewInventoryMaintain")
	public String viewInventoryMaintain() {
		return SUCCESS;
	}

	/** 物品领用 */
	// 查看
	@Action("viewArticleTook")
	public String viewArticleTook() {
		return SUCCESS;
	}

	/** 图书登记 */
	// 查看
	@Action("viewBookRegister")
	public String viewBookRegister() {
		return SUCCESS;
	}

	/** 借阅登记 */
	// 查看
	@Action("viewBorrowRegister")
	public String viewBorrowRegister() {
		return SUCCESS;
	}

	/** 归还登记 */
	// 查看
	@Action("viewRevertRegister")
	public String viewRevertRegister() {
		return SUCCESS;
	}

	/** 资产总类 */
	// 查看
	@Action("viewAssetsBigClass")
	public String viewAssetsBigClass() {

		return SUCCESS;
	}

	/** 资产分类 */
	// 查看
	@Action("viewAssetsSmallClass")
	public String viewAssetsSmallClass() {
		return SUCCESS;
	}

	/** 资产登记 */
	// 查看
	@Action("viewAssetsRegister")
	public String viewAssetsRegister() {
		if (application.getAssetsRegister() == null) {
			rec = "";
		}
		// this.bigClass = this.assetsBigClassService.getAll();
		return SUCCESS;
	}

	/********************************* 我的申请单 ************************/
	@Action("listappliction")
	public String listappliction() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				Application.class).add(
				Restrictions.eq("person.id", AppContext.getAccountContext()
						.getUser().getId()));
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getApplicationService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}

	@Action("viewApplication")
	public String viewApplication() {
		return SUCCESS;
	}

	@Action(value = "view", results = {
			@Result(name = "success", type = "redirect", location = "viewApplication?application=${application.getId()}"),
			@Result(name = "error", type = "chain", location = "listappliction") })
	public String view() {
		if (myApplyIds != null) {
			this.application = this.getApplicationService().get(myApplyIds[0]);

		}
		return SUCCESS;
	}

	/************** 待我审批 **************/
	@Action("listshenpi")
	public String listshenpi() {
		Person currentperson = AppContext.getAccountContext().currentUser();
		List<Application> ap = this.getApplicationService().getAllApp();
		for (Application ob : ap) {
			List<WorkFlowAndPerson> wf = this.getWorkFlowAndPersonService()
					.getWorkFlowAndPersonByApplication(ob.getWorkFlow(), ob);
			List<WorkFlowAndPerson> wff = sequens(wf);
			for (WorkFlowAndPerson obb : wff) {
				if ("1".equals(obb.getFlowstate())) {
					if ("1".equals(obb.getType())) {
						String[] personss = obb.getNodePersonId().split(",");
						for (String persons : personss) {
							System.out.println(persons);
							if ((currentperson.getId() + "").equals(persons)) {
								// 如果相同则 需要该人审签
								// 设置是否显示
								if (ob.getPersonAppProcess() != null) {
									String[] personapp = ob
											.getPersonAppProcess().split(",");
									for (String pa : personapp) {
										System.out.println(pa);
										if (currentperson.getResume().getName()
												.equals(pa)) {
											ob.setPersonAppState(2);
											ob.setShowState(AppContext
													.getAccountContext()
													.currentUser().getId()
													+ "：1");
											ob.setAppState(1);
											this.getApplicationService()
													.submit(ob);
											break;
										} else {
											ob.setShowState(AppContext
													.getAccountContext()
													.currentUser().getId()
													+ "：1");
											ob.setAppState(1);
											ob.setPersonAppState(1);
											this.getApplicationService()
													.submit(ob);
										}
									}
								} else {
									ob.setShowState(AppContext
											.getAccountContext().currentUser()
											.getId()
											+ "：1");
									ob.setAppState(1);
									ob.setPersonAppState(1);
									this.getApplicationService().submit(ob);
								}
							} else {

							}
						}
						break;
					}
					if ("2".equals(obb.getType())) {
						String[] personss = obb.getNodePersonId().split(",");
						for (String persons : personss) {
							if ((currentperson.getId() + "").equals(persons)) {
								// 如果相同则 需要该人审签
								// 设置是否显示
								if (ob.getPersonAppProcess() != null) {
									String[] personapp = ob
											.getPersonAppProcess().split(",");
									for (String pa : personapp) {
										System.out.println(pa);
										if (currentperson.getResume().getName()
												.equals(pa)) {
											ob.setPersonAppState(2);
											ob.setShowState(AppContext
													.getAccountContext()
													.currentUser().getId()
													+ "：1");
											ob.setAppState(1);
											this.getApplicationService()
													.submit(ob);
											break;
										} else {
											ob.setShowState(AppContext
													.getAccountContext()
													.currentUser().getId()
													+ "：1");
											ob.setAppState(1);
											ob.setPersonAppState(1);
											this.getApplicationService()
													.submit(ob);
										}
									}
								} else {
									ob.setShowState(AppContext
											.getAccountContext().currentUser()
											.getId()
											+ "：1");
									ob.setAppState(1);
									ob.setPersonAppState(1);
									this.getApplicationService().submit(ob);
								}
							} else {

							}
						}
						break;
					}
					if ("3".equals(obb.getType())) {
						String[] personss = obb.getNodePersonId().split(",");
						for (String persons : personss) {
							if ((currentperson.getId() + "").equals(persons)) {
								// 如果相同则 需要该人审签
								// 设置是否显示
								if (ob.getPersonAppProcess() != null) {
									String[] personapp = ob
											.getPersonAppProcess().split(",");
									for (String pa : personapp) {
										System.out.println(pa);
										if (currentperson.getResume().getName()
												.equals(pa)) {
											ob.setPersonAppState(2);
											ob.setShowState(AppContext
													.getAccountContext()
													.currentUser().getId()
													+ "：1");
											ob.setAppState(1);
											this.getApplicationService()
													.submit(ob);
											break;
										} else {
											ob.setShowState(AppContext
													.getAccountContext()
													.currentUser().getId()
													+ "：1");
											ob.setAppState(1);
											ob.setPersonAppState(1);
											this.getApplicationService()
													.submit(ob);
										}
									}
								} else {
									ob.setShowState(AppContext
											.getAccountContext().currentUser()
											.getId()
											+ "：1");
									ob.setAppState(1);
									ob.setPersonAppState(1);
									this.getApplicationService().submit(ob);
								}
							} else {

							}
						}
						break;
					}
					if ("5".equals(obb.getType())) {
						String[] personss = obb.getNodePersonId().split(",");
						for (String persons : personss) {
							if ((currentperson.getId() + "").equals(persons)) {
								// 如果相同则 需要该人审签
								// 设置是否显示
								if (ob.getPersonAppProcess() != null) {
									String[] personapp = ob
											.getPersonAppProcess().split(",");
									for (String pa : personapp) {
										System.out.println(pa);
										if (currentperson.getResume().getName()
												.equals(pa)) {
											ob.setPersonAppState(2);
											ob.setShowState(AppContext
													.getAccountContext()
													.currentUser().getId()
													+ "：1");
											this.getApplicationService()
													.submit(ob);
											break;
										} else {
											ob.setShowState(AppContext
													.getAccountContext()
													.currentUser().getId()
													+ "：1");

											ob.setPersonAppState(1);
											this.getApplicationService()
													.submit(ob);
										}
									}
								} else {
									ob.setShowState(AppContext
											.getAccountContext().currentUser()
											.getId()
											+ "：1");
									ob.setPersonAppState(1);
									this.getApplicationService().submit(ob);
								}
							} else {

							}
						}
						break;
					}
				}
			}
		}

		// Integer role =
		// AppContext.getAccountContext().getUser().getRole().getId();
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				Application.class);
		criteria.add(Restrictions.isNotNull("workFlow"));
		criteria.add(Restrictions.eq("appState", 1));
		criteria.add(Restrictions.eq("showState", AppContext
				.getAccountContext().currentUser().getId()
				+ "：1"));
		criteria.add(Restrictions.eq("personAppState", 1));
		// if(role == 1){
		// criteria.add(Restrictions.eq("spr", 1));
		// }else if(role == 6){
		// criteria.add(Restrictions.eq("spr", 2));
		// }else if(role == 7){
		// criteria.add(Restrictions.eq("spr", 3));
		// }else if(role == 10){
		// criteria.add(Restrictions.eq("spr", 5));
		// }else if(role == 9){
		// criteria.add(Restrictions.eq("spr", 4));
		// }
		this.setPagination(this.applicationService.listByPage(criteria, this
				.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}

	public static List<WorkFlowAndPerson> sequens(List<WorkFlowAndPerson> ss) {
		List<WorkFlowAndPerson> returnlist = new ArrayList<WorkFlowAndPerson>();
		int slength = ss.size();
		for (int i = 0; i < slength; i++) {

			for (WorkFlowAndPerson uo : ss) {
				if (uo.getFlowsequen().equals(i + "")) {
					returnlist.add(uo);
				}
			}
		}
		return returnlist;

	}

	/***************************** 审批监控 *******************************/
	@Action("listMonitoring")
	public String listMonitoring() {
		Person person=AppContext.getAccountContext().currentUser();
		List<Application> df=this.getApplicationService().getAllApp();
		for (Application dfs : df) {
			List<ShenQingType> dt=this.getShenQingTypeService().getShenQingTypeByName(dfs.getShenqingTypeName());
			for (ShenQingType dts : dt) {
				if (dts.getJiankong()==null || "".equals(dts.getJiankong().trim()) || "0".equals(dts.getJiankong().trim())) {
					dfs.setJkState(5);
					this.getApplicationService().submit(dfs);
				}else{
					String[] per=dts.getJiankong().split(",");
					for (String pers : per) {
						if (person.getResume().getName().equals(pers)) {
							dfs.setJkState(0);
							this.getApplicationService().submit(dfs);
							break;
						}else{
							dfs.setJkState(0);
							this.getApplicationService().submit(dfs);
						}
					}
				}
			}
		}
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				Application.class);
		criteria.add(Restrictions.eq("oabox", 0));
		criteria.add(Restrictions.eq("jkState", 0));
		this.setPagination(this.applicationService.listByPage(criteria, this
				.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}

	/****************************** 待我阅读 *****************************/
	 @Action("listReading")
	 public String listReading(){
	 List<Application> ap=this.getApplicationService().getAllApp();
	 for (Application app : ap) {
		if (app.getReadPersons()==null || "".equals(app.getReadPersons().trim())) {
			app.setShowReady(AppContext.getAccountContext().currentUser().getId()+.0);
			this.getApplicationService().submit(app);
		}else{
			String[] reper=app.getReadPersons().split(",");
			for (String rep : reper) {
				if (AppContext.getAccountContext().currentUser().getResume().getName().equals(rep)) {
					if (app.getAlreadyReadyPerson()==null || "".equals(app.getAlreadyReadyPerson().trim())) {
						app.setIsReadys("否");
						app.setShowReady(AppContext.getAccountContext().currentUser().getId()+.1);
						this.getApplicationService().submit(app);
						break;
					}else{
						String[] alPer=app.getAlreadyReadyPerson().split(",");
						for (String alpers : alPer) {
							if (AppContext.getAccountContext().currentUser().getResume().getName().equals(alpers)) {
								app.setIsReadys("是");
								app.setShowReady(AppContext.getAccountContext().currentUser().getId()+.1);
								this.getApplicationService().submit(app);
								break;
							}else{
								app.setIsReadys("否");
								app.setShowReady(AppContext.getAccountContext().currentUser().getId()+.1);
								this.getApplicationService().submit(app);
							}
						}
					}
					break;
				}else{
					app.setShowReady(AppContext.getAccountContext().currentUser().getId()+.0);
					this.getApplicationService().submit(app);
				}
			}
		}
	}
	 DetachedCriteria criteria = this.getPaginationHelper().createQuery(Application.class);
	criteria.add(Restrictions.eq("showReady", AppContext.getAccountContext().currentUser().getId()+.1));
	 this.setPagination(this.applicationService.listByPage(criteria, this.getPaginationHelper().prepare(pagination)));
	 return SUCCESS;
	 }
	/****************************** 撤销申请 *****************************/
	@Action(value = "revoked", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "listappliction") })
	public String revoked() {
		// System.out.println(application.getId());
		this.getApplicationService().remove(application);
		return SUCCESS;
	}

	/*********************** 差旅副表字段 *************************/
	private String[] startdate;
	private String[] enddate;
	private String[] address;
	private String[] plane;
	private String[] car;
	private String[] sleep;
	private String[] night;
	private String[] city;
	private String[] zhusu;
	private String[] buzu;
	private String[] qita;
	private String[] heji;

	public String[] getStartdate() {
		return startdate;
	}

	public void setStartdate(String[] startdate) {
		this.startdate = startdate;
	}

	public String[] getEnddate() {
		return enddate;
	}

	public void setEnddate(String[] enddate) {
		this.enddate = enddate;
	}

	public String[] getAddress() {
		return address;
	}

	public void setAddress(String[] address) {
		this.address = address;
	}

	public String[] getPlane() {
		return plane;
	}

	public void setPlane(String[] plane) {
		this.plane = plane;
	}

	public String[] getCar() {
		return car;
	}

	public void setCar(String[] car) {
		this.car = car;
	}

	public String[] getSleep() {
		return sleep;
	}

	public void setSleep(String[] sleep) {
		this.sleep = sleep;
	}

	public String[] getNight() {
		return night;
	}

	public void setNight(String[] night) {
		this.night = night;
	}

	public String[] getCity() {
		return city;
	}

	public void setCity(String[] city) {
		this.city = city;
	}

	public String[] getZhusu() {
		return zhusu;
	}

	public void setZhusu(String[] zhusu) {
		this.zhusu = zhusu;
	}

	public String[] getBuzu() {
		return buzu;
	}

	public void setBuzu(String[] buzu) {
		this.buzu = buzu;
	}

	public String[] getQita() {
		return qita;
	}

	public void setQita(String[] qita) {
		this.qita = qita;
	}

	public String[] getHeji() {
		return heji;
	}

	public void setHeji(String[] heji) {
		this.heji = heji;
	}

	private void initchailvs() {
		for (int i = 0; i < car.length; i++) {
			this.chailv = new ChaiLv();
			if (ids != null) {
				this.chailv.setId(ids[i]);
			}
			this.chailv.setStartDate(startdate[i]);
			this.chailv.setEndDate(enddate[i]);
			this.chailv.setArrival(address[i]);
			this.chailv.setPlane(Double.parseDouble(plane[i]));
			this.chailv.setCar(Double.parseDouble(car[i]));
			this.chailv.setCity(Double.parseDouble(city[i]));
			this.chailv.setBuzhu(Double.parseDouble(buzu[i]));
			this.chailv.setQita(Double.parseDouble(qita[i]));
			this.chailv.setHeji(Double.parseDouble(heji[i]));
			this.chailv.setSleep(Double.parseDouble(sleep[i]));
			this.chailv.setNight(Double.parseDouble(night[i]));
			this.chailv.setZhusu(Double.parseDouble(zhusu[i]));
			this.chailv.setApplication(application);
			this.chailvService.save(chailv);
			this.application.addChailv(chailv);
		}
	}

	/**************************** 报价副表 *****************************/
	private void initquote() {
		for (int i = 0; i < qname.length; i++) {
			Quote quote = new Quote();
			if (id != null) {
				quote.setId(id[i]);
			}
			quote.setName(qname[i]);
			quote.setSpecifications(gui[i]);
			quote.setUnits(dan[i]);
			quote.setUnitPrice(price[i]);
			quote.setNumber(shu[i]);
			quote.setMoney(jin[i]);
			quote.setRemark(bei[i]);
			quote.setApplication(application);
			this.quoteService.save(quote);
			this.application.addQuotes(quote);
			// this.quotes.add(quote);
		}
	}

	private Integer[] id;
	private String[] qname;
	private String[] gui;
	private String[] dan;
	private String[] price;
	private String[] shu;
	private String[] jin;
	private String[] bei;

	public Integer[] getId() {
		return id;
	}

	public void setId(Integer[] id) {
		this.id = id;
	}

	public String[] getQname() {
		return qname;
	}

	public void setQname(String[] qname) {
		this.qname = qname;
	}

	public String[] getGui() {
		return gui;
	}

	public void setGui(String[] gui) {
		this.gui = gui;
	}

	public String[] getDan() {
		return dan;
	}

	public void setDan(String[] dan) {
		this.dan = dan;
	}

	public String[] getPrice() {
		return price;
	}

	public void setPrice(String[] price) {
		this.price = price;
	}

	public String[] getShu() {
		return shu;
	}

	public void setShu(String[] shu) {
		this.shu = shu;
	}

	public String[] getJin() {
		return jin;
	}

	public void setJin(String[] jin) {
		this.jin = jin;
	}

	public String[] getBei() {
		return bei;
	}

	public void setBei(String[] bei) {
		this.bei = bei;
	}

	/********************* 采购单副表 ************************/
	private void initprocure() {
		for (int i = 0; i < bei.length; i++) {
			Procure procure = new Procure();
			if (id != null) {
				procure.setId(id[i]);
			}
			procure.setNum(gui[i]);
			procure.setParam(dan[i]);
			procure.setPname(qname[i]);
			procure.setCount(Double.parseDouble(shu[i]));
			procure.setMoney(Double.parseDouble(jin[i]));
			procure.setRemark(bei[i]);
			procure.setApplication(application);
			this.procureService.save(procure);
			this.application.addProcures(procure);
		}
	}

	/**************************************** 审批 ******************************************/
	private String yijian;

	public String getYijian() {
		return yijian;
	}

	public void setYijian(String yijian) {
		this.yijian = yijian;
	}

	@Action("listJingWo")
	public String listJingWo() {
		Person currentperson = AppContext.getAccountContext().currentUser();
		List<Application> ap = this.getApplicationService().getAllApp();
		for (Application ob : ap) {
			List<WorkFlowAndPerson> wf = this.getWorkFlowAndPersonService()
					.getWorkFlowAndPersonByApplication(ob.getWorkFlow(), ob);
			List<WorkFlowAndPerson> wff = sequens(wf);
			for (WorkFlowAndPerson obb : wff) {
				if ("2".equals(obb.getFlowstate())) {
					String[] personss = obb.getNodePersonId().split(",");
					for (String persons : personss) {
						System.out.println(persons);
						if ((currentperson.getId() + "").equals(persons)) {
							ob.setJingwoShowState(AppContext
									.getAccountContext().currentUser().getId()
									+ "：1");
							this.getApplicationService().submit(ob);
						} else {
							break;
						}
					}
				}
			}
		}
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				Application.class);
		criteria.add(Restrictions.isNotNull("workFlow"));
		criteria.add(Restrictions.eq("jingwoShowState", AppContext
				.getAccountContext().currentUser().getId()
				+ "：1"));
		criteria.add(Restrictions.or(Restrictions.eq("appState", 2),
				Restrictions.eq("appState", 4)));
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getApplicationService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}

	// //////同意
	@Action(value = "agree", results = {
			@Result(name = "success", type = "redirect", location = "listJingWo"),
			@Result(name = "error", type = "chain", location = "listappliction") })
	public String agree() {
		Integer role = AppContext.getAccountContext().getUser().getRole()
				.getId();
		if ("采购申请".equals(application.getResign())
				|| "物品领用".equals(application.getResign())) {
			application.setSqType(2);
			application.setSpr(0);
		} else {
			switch (role) {
			case 1:
				application.setSpr(2);
				break;
			case 7:
				application.setSpr(3);
				break;
			case 10:
				application.setSpr(0);
				break;
			case 9:
				application.setSpr(4);
				break;
			}
		}
		if (role == 10) {
			application.setSqType(2);
		}
		application.setState("经我审批");
		List<Approve> apps = new ArrayList<Approve>();
		Approve app = new Approve();
		app.setApplication(application);
		app.setYijian("同意");
		app.getApplication().getPurchaseApply().setPa_examineState(2);
		apps.add(app);
		application.setApproves(apps);
		this.applicationService.save(application);
		return SUCCESS;
	}

	// //////不同意
	@Action(value = "notagree", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "listappliction") })
	public String notagree() {
		application.setSqType(4);
		application.setSpr(0);
		this.applicationService.saveanddel(application);
		return SUCCESS;
	}

	@Action(value = "saveFinish", results = { @Result(name = "success", type = "redirect", location = "listshenpi") })
	public String saveFinish() {
		System.out.println(AppContext.getAccountContext().currentUser()
				.getResume().getName()
				+ "审核");
		List<WorkFlowAndPerson> wf = this.getWorkFlowAndPersonService()
				.getWorkFlowAndPersonByApplication(application.getWorkFlow(),
						application);
		List<WorkFlowAndPerson> wfp = sequens(wf);
		for (WorkFlowAndPerson wff : wfp) {
			if ("1".equals(wff.getFlowstate())) {
				String[] personss = wff.getNodePersonId().split(",");
				for (String persons : personss) {
					if ((AppContext.getAccountContext().currentUser().getId() + "")
							.equals(persons)) {
						FlowVerifyDetail details = new FlowVerifyDetail();
						if (upload != null) {
							this.flowVerifyDetail.setAttach(FileUtil
									.getInstance().createAttach(upload,
											uploadFileName));
							details.setAttach(flowVerifyDetail.getAttach());
						}
						details.setWorkFlowAndPerson(wff);
						details.setExecutor(AppContext.getAccountContext()
								.currentUser());
						details.setResult(flowVerifyDetail.getResult());
						details.setOpinion(flowVerifyDetail.getOpinion());
						this.getFlowVerifyDetailService().save(details);
						if ("5".equals(wff.getType())) {// 如果该节点是结束节点时，审核完成
							if (wff.getPersonNum() == 1) {
								if (flowVerifyDetail.getResult() == 4) {
									wff.setFlowstate("2");
									wff.setPersonNum(wff.getPersonNum() - 1);
									this.getWorkFlowAndPersonService().submit(
											wff);
									application.setAppFlow("审核完成");
									application.setAppState(4);
									application.setPersonAppProcess("");
									application.setPersonAppState(2);
									this.getApplicationService().submit(
											application);
									this.setPrompt("提交成功");
									return SUCCESS;
								} else if (flowVerifyDetail.getResult() == 1) {
									wff.setFlowstate("2");
									wff.setPersonNum(wff.getPersonNum() - 1);
									this.getWorkFlowAndPersonService().submit(
											wff);
									application.setAppFlow("审核完成");
									application.setAppState(2);
									application.setShowState("2");
									application.setPersonAppProcess("");
									application.setPersonAppState(2);
									this.getApplicationService().submit(
											application);
									this.setPrompt("提交成功");
									return SUCCESS;
								}
								break;
							} else {
								if (flowVerifyDetail.getResult() == 4) {
									wff.setFlowstate("2");
									wff.setPersonNum(wff.getPersonNum() - 1);
									this.getWorkFlowAndPersonService().submit(
											wff);
									application.setAppFlow("审核完成");
									application.setAppState(4);
									application.setPersonAppProcess("");
									application.setPersonAppState(2);
									this.getApplicationService().submit(
											application);
									this.setPrompt("提交成功");
									return SUCCESS;
								} else if (flowVerifyDetail.getResult() == 1) {
									wff.setPersonNum(wff.getPersonNum() - 1);
									this.getWorkFlowAndPersonService().submit(
											wff);
									application.setAppFlow(AppContext
											.getAccountContext().currentUser()
											.getResume().getName()
											+ "审核");
									application.setShowState("2");
									application.setPersonAppState(2);
									if (application.getPersonAppProcess() == null
											|| "".equals(application
													.getPersonAppProcess()
													.trim())) {
										application.setPersonAppProcess(AppContext
												.getAccountContext()
												.currentUser().getResume()
												.getName());
									} else {
										application.setPersonAppProcess(application
												.getPersonAppProcess()
												+ ","
												+ AppContext
														.getAccountContext()
														.currentUser()
														.getResume().getName());
									}
									this.getApplicationService().submit(
											application);
									this.setPrompt("提交成功");
									return SUCCESS;
								}
								break;
							}
						} else {
							if (wff.getPersonNum() == 1) {
								if (flowVerifyDetail.getResult() == 4) {
									wff.setFlowstate("2");
									wff.setPersonNum(wff.getPersonNum() - 1);
									this.getWorkFlowAndPersonService().submit(
											wff);
									application.setAppState(4);
									application.setAppFlow("审核完成");
									application.setPersonAppProcess("");
									application.setPersonAppState(2);
									System.out.println(application
											.getAppState());
									this.getApplicationService().submit(
											application);
									this.setPrompt("提交成功");
									return SUCCESS;
								} else if (flowVerifyDetail.getResult() == 1) {
									wff.setFlowstate("2");
									wff.setPersonNum(wff.getPersonNum() - 1);
									this.getWorkFlowAndPersonService().submit(
											wff);
									application.setShowState("2");
									application.setAppFlow(AppContext
											.getAccountContext().currentUser()
											.getResume().getName()
											+ "审核");
									application.setPersonAppProcess("");
									application.setPersonAppState(2);
									this.getApplicationService().submit(
											application);
									this.setPrompt("提交成功");
									return SUCCESS;
								}
								break;
							} else {
								if (flowVerifyDetail.getResult() == 4) {
									wff.setPersonNum(wff.getPersonNum() - 1);
									this.getWorkFlowAndPersonService().submit(
											wff);
									application.setAppState(4);
									application.setAppFlow("审核完成");
									application.setPersonAppProcess("");
									application.setPersonAppState(2);
									System.out.println(application
											.getAppState());
									this.getApplicationService().submit(
											application);
									this.setPrompt("提交成功");
									return SUCCESS;
								} else if (flowVerifyDetail.getResult() == 1) {
									wff.setPersonNum(wff.getPersonNum() - 1);
									this.getWorkFlowAndPersonService().submit(
											wff);
									application.setShowState("2");
									application.setAppFlow(AppContext
											.getAccountContext().currentUser()
											.getResume().getName()
											+ "审核");
									application.setPersonAppState(2);
									if (application.getPersonAppProcess() == null
											|| "".equals(application
													.getPersonAppProcess()
													.trim())) {
										application.setPersonAppProcess(AppContext
												.getAccountContext()
												.currentUser().getResume()
												.getName());
									} else {
										application.setPersonAppProcess(application
												.getPersonAppProcess()
												+ ","
												+ AppContext
														.getAccountContext()
														.currentUser()
														.getResume().getName());
									}
									this.getApplicationService().submit(
											application);
									this.setPrompt("提交成功");
									return SUCCESS;
								}
								break;
							}
						}
					}
				}
			}
		}
		return SUCCESS;
	}

	@Action("viewAppCash")
	public String viewAppCash() {
		return SUCCESS;
	}

	@Action("viewAppCheque")
	public String viewAppCheque() {
		return SUCCESS;
	}

	@Action("viewAppDianHui")
	public String viewAppDianHui() {
		return SUCCESS;
	}

	@Action("viewAppcost")
	public String viewAppcost() {
		purposelist = this.purposeService.getAllpurpose();
		return SUCCESS;
	}

	@Action("viewAppChailv")
	public String viewAppChailv() {
		return SUCCESS;
	}

	@Action("viewAppReport")
	public String viewAppReport() {
		return SUCCESS;
	}

	@Action("viewAppQuote")
	public String viewAppQuote() {
		return SUCCESS;
	}

	@Action("viewAppFault")
	public String viewAppFault() {
		return SUCCESS;
	}

	@Action("viewAppProcure")
	public String viewAppProcure() {
		return SUCCESS;
	}

	@Action("viewAppBusiness")
	public String viewAppBusiness() {
		return SUCCESS;
	}

	@Action("viewAppChuchai")
	public String viewAppChuchai() {
		return SUCCESS;
	}

	@Action("viewAppLeave")
	public String viewAppLeave() {
		return SUCCESS;
	}

	@Action("viewAppOverTime")
	public String viewAppOverTime() {
		return SUCCESS;
	}

	@Action("viewAppPersonnel")
	public String viewAppPersonnel() {
		return SUCCESS;
	}

	@Action("viewAppDismiss")
	public String viewAppDismiss() {
		return SUCCESS;
	}

	@Action("viewAppBecomes")
	public String viewAppBecomes() {
		return SUCCESS;
	}

	@Action("viewAppProbation")
	public String viewAppProbation() {
		return SUCCESS;
	}

	@Action("viewAppWage")
	public String viewAppWage() {
		return SUCCESS;
	}

	@Action("viewAppRecruitment")
	public String viewAppRecruitment() {
		return SUCCESS;
	}

	@Action("viewAppLiZhi")
	public String viewAppLiZhi() {
		return SUCCESS;
	}

	@Action("viewAppJiangcheng")
	public String viewAppJiangcheng() {
		return SUCCESS;
	}

	/*** 归档 ****/
	@Action(value = "saveFilling", results = {
			@Result(name = "success", type = "redirect", location = "listMonitoring"),
			@Result(name = "error", type = "chain", location = "viewReceiptRegister"), })
	public String saveFilling() {
		if (ids != null) {
			this.application = this.getApplicationService().get(ids[0]);
		}
		this.archivesType = this.archivesTypeService.get(idd);
		if (application.getAppState()!=2 && application.getAppState()!=4) {
			this.addActionError("该任务还在审批中，不能归档");
			return ERROR;
		}
		ArchivesManager am = new ArchivesManager();
		am.setArchivesType(archivesType);
		am.setNumber("TRACIN" + new Date().getTime() + "V");
		am.setArchivesName(application.getAppName());
		am.setDegree(application.getType());
		am.setSendTime(application.getRecordTime());
		am.setSendPerson(application.getRecorder());
		am.setState(0);
		if (application.getAttach() != null) {
			am.setAttach(application.getAttach());
		}
		am.setMark(1);
		this.getArchivesManagerService().save(am);
		application.setOabox(1);// 1为归档
		this.getApplicationService().submit(application);
		return SUCCESS;
	}
	@Action("editReady")
	public String editReady(){
		return SUCCESS;
	}
	@Action(value = "saveReady", results = {
			@Result(name = "success", type = "redirect", location = "listappliction"),
			@Result(name = "error", type = "chain", location = "editReady"), })
	public String saveReady(){
		Date dt=new Date();
		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
		application.setDateTime(sf.format(dt));
		application.setIsReadys("否");
		application.setFenPerson(AppContext.getAccountContext().currentUser());
		this.getApplicationService().submit(application);
		return SUCCESS;
	}
	@Action(value = "saveWaitMyReady", results = {
			@Result(name = "success", type = "redirect", location = "listReading"),
			@Result(name = "error", type = "chain", location = "editReady"), })
	public String saveWaitMyReady(){
		application.setIsReadys("是");
		if (application.getAlreadyReadyPerson()==null || "".equals(application.getAlreadyReadyPerson().trim())) {
			application.setAlreadyReadyPerson(AppContext.getAccountContext().currentUser().getResume().getName());
		}else{
			application.setAlreadyReadyPerson(application.getAlreadyReadyPerson()+","+AppContext.getAccountContext().currentUser().getResume().getName());
		}
		this.getApplicationService().submit(application);
		return SUCCESS;
	}
	/***
	 * 根据类型进行编码的保存
	 * 
	 * @param type
	 */
	public String getCode(String type) {
	    AutoCode alist=this.getAutoCodeService().getTaskRemind(type);
	    Date dat=new Date();
	    SimpleDateFormat adf=new SimpleDateFormat("yyyyMMdd");
	    String date=adf.format(dat);
	    if(alist==null)
	    {//初始的时候调用
		    AutoCode  ac=new AutoCode();
		    ac.setCodeType(type);
		    ac.setCodeValue(type+date+"0000001");
		    ac.setAddValue("0000001");
		    this.getAutoCodeService().save(ac);	
		    return type+date+"0000001";
	    }else{
	    	String vac=alist.getAddValue();
	    	AutoCode alistA=this.getAutoCodeService().getTaskRemind(type);
	    	alistA.setCodeValue(type+date+new AutoCodeAction().addCodes(vac));
	    	alistA.setAddValue(new AutoCodeAction().addCodes(vac));
		    this.getAutoCodeService().submit(alistA);	
		    return type+date+new AutoCodeAction().addCodes(vac);
	    }
	}
	@Action(value = "viewApplica", results = { @Result(name = "error", type = "chain", location = "listappliction") })
	public String viewApplica(){
		if (myApplyIds!=null) {
			this.application=this.getApplicationService().get(myApplyIds[0]);
			this.workFlowAndPersons=this.getWorkFlowAndPersonService().getWorkFlowAndPersonByApplication(application.getWorkFlow(), application);
			this.flowVerifyDetails=this.getFlowVerifyDetailService().getAllFlowVerifyDetails();
			return SUCCESS;
		}else{
			this.addActionError("请选择数据！");
			return ERROR;
		}
	}
}
